<template>
	<view class="queuing_subsidy">
		<view class="head_box">
			<view class="shop_box">
				<view class="shop_left">
					<image class="head_img" :src="$util.img(shopHerd.logo)" mode=""></image>
					<view class="shop_con">
						<view class="shop_name">{{shopHerd.site_name}}</view>
						<view class="shop_industry">{{stateText(shopHerd.shop_status)}}｜{{shopHerd.category_name}}
						</view>
					</view>
				</view>
				<view class=""></view>
			</view>
			<view class="menus_box">
				<view class="menu_item" :class="current_menu == menu_index ? 'native' : ''"
					v-for="(menu_item,menu_index) in menus" :key="menu_index" @click="selectIndex(menu_index)">
					{{menu_item}}
				</view>
			</view>
		</view>
		<mescroll-uni @getData="getData" ref="mescroll" top="296">
			<block slot="list">
				<block v-if="dataList.length > 0">
					<view class="list-box">
						<view class="list-item" v-for="(item,index) in dataList" :key="">
							<view class="part-one">
								<view class="part-o-left">
									<view class="order_label">订单 {{item.order_no}}</view>
								</view>
								<view class="order_state" :class="item.state == 2 ? 'completed' : 0">
									{{orderText(item.state)}}
								</view>
							</view>
							<view class="content_box">
								<view class="orders-box">
									<view class="order-item">
										<view class="num_text">{{item.account}}</view>
										<view class="dec_text">订单积分</view>
									</view>
									<view class="order-item">
										<view class="num_text">{{item.total_expansion_value}}</view>
										<view class="dec_text">补贴额度</view>
									</view>
									<view class="order-item">
										<view class="num_text">{{item.platform}}</view>
										<view class="dec_text">平台加速</view>
									</view>
									<view class="order-item"
										@click="$util.redirectTo('/plugpages/subsidy/accelerate_order_details/accelerate_order_details',{order_no:item.order_no})">
										<view class="num_text red">{{item.accelerate}}</view>
										<view class="nagation_box">
											<view class="dec_text auto">加速补贴</view>
											<image :src="$util.img('upload/uniapp/subsidy/item_right@2x.png')" mode="">
											</image>
										</view>
									</view>
								</view>
								<view class="prograss-box">
									<view class="active_prograss" :style="{width:item.progress + '%'}"
										v-if="item.progress > 0">
										<view class="slider_box">{{item.progress}}%</view>
									</view>
								</view>
								<view class="finish_dec">
									<view class="finish_item">
										<view class="dec_gray">补贴进度</view>
										<view class="dec_red">{{item.progress}}%</view>
									</view>
									<view class="finish_item">
										<view class="dec_gray">当前排名</view>
										<view class="dec_red">第{{item.rank}}名</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				<block v-else>
					<ns-empty :isIndex="false" :fixed="!1" text="暂无数据"></ns-empty>
				</block>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menus: ['全部', '加速中', '排队中', '已完成'],
				current_menu: 0,
				dataList: [],
				site_id: '',
				shopHerd: {}
			};
		},
		onLoad(opts) {
			if (opts.site_id) {
				this.site_id = opts.site_id;
			}
		},
		methods: {
			getData(mescroll) {
				if (mescroll.num == 1) {
					this.getShopHerd();
				}
				this.$api.sendRequest({
					url: '/expansion/api/Record/shopQueuePage',
					data: {
						page: mescroll.num,
						page_size: mescroll.size,
						type: this.current_menu,
						site_id: this.site_id
					},
					success: res => {
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data) {
							newArr = res.data.list;
						} else {
							this.$util.showToast({
								title: msg
							});
						}
						if (mescroll.endSuccess) mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
						this.dataList = this.dataList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail() {
						//联网失败的回调
						if (mescroll.endErr) mescroll.endErr();
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				})
			},
			getShopHerd() {
				this.$api.sendRequest({
					url: '/expansion/api/Record/getShopHerd',
					data: {
						site_id: this.site_id
					},
					success: res => {
						if (res.code == 0) {
							this.shopHerd = res.data;
						}
					}
				})
			},
			selectIndex(index) {
				if (this.current_menu != index) {
					this.current_menu = index;
					this.$refs.mescroll.refresh();
				}
			},
			stateText(state) {
				if (state == 0) {
					return '关闭'
				} else if (state == 1) {
					return '正常'
				} else {
					return '审核中'
				}
			},
			orderText(state) {
				if (state == 0) {
					return '排队中';
				} else if (state == 1) {
					return '加速中';
				} else {
					return '已完成';
				}
			},
			stateColor(state) {
				if (state == 0 || state == 1) {
					return '';
				} else {
					return 'completed'
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.queuing_subsidy {
		.head_box {
			width: 100vw;

			.shop_box {
				width: 100%;
				height: 200rpx;
				background-color: #fff;
				padding-left: 24rpx;
				padding-right: 32rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.shop_left {
					display: flex;
					align-items: center;

					.head_img {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;
					}

					.shop_con {
						margin-left: 24rpx;

						.shop_name {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 32rpx;
							color: #222222;
							line-height: 44rpx;
						}

						.shop_industry {
							margin-top: 8rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #666666;
							line-height: 34rpx;
						}
					}
				}

				.right_icon {
					width: 48rpx;
					height: 48rpx;
				}
			}

			.menus_box {
				width: 100%;
				height: 96rpx;
				display: flex;
				align-items: center;

				.menu_item {
					width: 25%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #222222;
					line-height: 42rpx;

					&.native {
						font-weight: 500;
						font-size: 32rpx;
					}
				}
			}
		}

		.list-box {
			padding: 0 24rpx;

			.list-item {
				padding: 28rpx 24rpx 34rpx 24rpx;
				background-color: #FFFFFF;
				border-radius: 20rpx;
				margin-bottom: 24rpx;

				.part-one {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.part-o-left {
						display: flex;
						align-items: center;

						.order_label {
							margin-left: 8rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #666666;
							line-height: 40rpx;
						}
					}

					.order_state {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #F53F3F;

						&.completed {
							color: #666666;
						}
					}
				}

				.content_box {
					margin-top: 24rpx;
					padding: 28rpx 24rpx;
					background-color: #F2F3F5;
					border-radius: 12rpx;

					.orders-box {
						display: flex;

						.order-item {
							width: 25%;
							display: flex;
							align-items: center;
							flex-direction: column;

							.nagation_box {
								width: 100%;
								display: flex;
								align-items: center;

								image {
									width: 32rpx;
									height: 32rpx;
								}
							}

							.num_text {
								width: 100%;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 32rpx;
								color: #222222;
								line-height: 46rpx;

								&.red {
									color: #F53F3F;
								}

								// text-align: left;
							}
						}
					}

					.prograss-box {
						margin-top: 38rpx;
						width: 100%;
						height: 24rpx;
						background-color: #DCDCDC;
						border-radius: 38rpx;

						.active_prograss {
							height: 100%;
							border-radius: 38rpx;
							background-color: #F53F3F;
							position: relative;

							.slider_box {
								position: absolute;
								right: -16rpx;
								top: -6rpx;
								width: 68rpx;
								height: 36rpx;
								background: #F53F3F;
								border-radius: 60rpx 60rpx 60rpx 60rpx;
								border: 2rpx solid #FFFFFF;

								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 22rpx;
								color: #FFFFFF;
								line-height: 30rpx;
								display: flex;
								align-items: center;
								justify-content: center;
							}
						}
					}

					.finish_dec {
						margin-top: 22rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.finish_item {
							display: flex;
							align-items: center;

							.dec_gray {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #666666;
								line-height: 34rpx;
							}

							.dec_red {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
								color: #F53F3F;
								line-height: 34rpx;
							}
						}
					}
				}
			}
		}
	}

	.dec_text {
		margin-top: 4rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		line-height: 34rpx;
		width: 100%;
	}

	.auto {
		width: auto;
	}

	page {
		background-color: #F2F3F5;
	}

	view {
		box-sizing: border-box;
	}
</style>